﻿using CloudFranceTriple.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using System;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace CloudFranceTriple.Tests.Areas.Settings
{
    [TestClass]
    public class EventCategoryControllerTest : UnitTestBase
    {
        private Int32 _unitTestEventCategoryId = 9; // Maintenance

        [TestMethod]
        [TestCategory("Settings.EventCategory")]
        public void EventCategoryController_Create_Post_ModelIsValid()
        {
            // Arrange
            var controller = new CloudFranceTriple.WebRole.Areas.Settings.Controllers.EventCategoryController();

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            var _now = DateTime.UtcNow;
            var eventCategoryset = new EventCategorySet
            {
                LabelEventCategory = "Unit Test - Event Category",
                OrderEventCategory = 0,
                BackColorEventCategory = "fffffe",
                ColorEventCategory = "111111"
            };

            // Act
            var result = controller.Create(eventCategoryset) as RedirectToRouteResult;


            UnitTestEventCategoryId = eventCategoryset.Id;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Settings.EventCategory")]
        public void EventCategoryController_Index()
        {
            // Arrange
            var controller = new CloudFranceTriple.WebRole.Areas.Settings.Controllers.EventCategoryController();

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.Index() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Settings.EventCategory")]
        public void EventCategoryController_Details()
        {
            // Arrange
            var controller = new CloudFranceTriple.WebRole.Areas.Settings.Controllers.EventCategoryController();

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.Details(_unitTestEventCategoryId) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Settings.EventCategory")]
        public void EventCategoryController_Create_Get()
        {
            // Arrange
            var controller = new CloudFranceTriple.WebRole.Areas.Settings.Controllers.EventCategoryController();

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.Create() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Settings.EventCategory")]
        public void EventCategoryController_Edit_Get()
        {
            // Arrange
            var controller = new CloudFranceTriple.WebRole.Areas.Settings.Controllers.EventCategoryController();

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.Edit(_unitTestEventCategoryId) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Settings.EventCategory")]
        public void EventCategoryController_Edit_Post()
        {
            // Arrange
            var controller = new CloudFranceTriple.WebRole.Areas.Settings.Controllers.EventCategoryController();

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            var _now = DateTime.UtcNow;
            var eventCategoryset = new EventCategorySet
            {
                Id = _unitTestEventCategoryId,
                LabelEventCategory = "Unit Test - Event Category",
                OrderEventCategory = 0,
                BackColorEventCategory = "fffffe",
                ColorEventCategory = "111111"
            };

            // Act
            var result = controller.Edit(eventCategoryset) as RedirectToRouteResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Settings.EventCategory")]
        public void EventCategoryController_Delete_Get()
        {
            // Arrange
            var controller = new CloudFranceTriple.WebRole.Areas.Settings.Controllers.EventCategoryController();

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.Delete(_unitTestEventCategoryId) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Settings.EventCategory")]
        public void EventCategoryController_DeleteConfirmed_Post()
        {
            // Arrange
            var controller = new CloudFranceTriple.WebRole.Areas.Settings.Controllers.EventCategoryController();

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.DeleteConfirmed(UnitTestEventCategoryId) as RedirectToRouteResult;

            // Assert
            Assert.IsNotNull(result);
        }
    }
}
